/*
 * @Description:
 * @Version: 2.0
 * @Autor: Seven
 * @Date: 2023-10-23 10:17:55
 * @LastEditors: Seven
 * @LastEditTime: 2023-10-23 10:18:08
 */
//本地存储
class Cache {
  constructor(isLocal) {
    this.storage = isLocal ? localStorage : sessionStorage;
  }
  setCache(key, value) {
    if (!value) {
      throw new Error("value erroe: value必须有值");
    } else {
      this.storage.setItem(key, JSON.stringify(value));
    }
  }
  getCache(key) {
    const result = this.storage.getItem(key);
    if (result) {
      return JSON.parse(result);
    }
  }
  removeCache(key) {
    this.storage.removeItem(key);
  }
  clear() {
    this.storage.clear();
  }
}
export const loacalCache = new Cache(true);
export const sessionCache = new Cache(false);
